package com.jxinternet.platform.services.repository.convert;

import com.jxinternet.platform.services.entity.cassandra.WealthCassandra;
import com.jxinternet.platform.services.entity.domian.Wealth;
import com.jxinternet.platform.services.entity.mysql.WealthMysql;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/8/22.
 */
@Service
public class WealthContert implements BaseConvert<Wealth,WealthMysql,WealthCassandra> {

    @Override
    public WealthMysql convertMysql(Wealth wealth) {
        if (wealth == null) {
            return null;
        }

        return copyEntityToMysql(wealth);
    }

    @Override
    public WealthCassandra convertCassandra(Wealth wealth) {
        if (wealth == null) {
            return null;
        }
        return copyEntityToCassandra(wealth);
    }

    @Override
    public Wealth convertMysqlDomainToModel(WealthMysql wealthMysql) {
        if (wealthMysql == null) {
            return null;
        }
        return copyMysqlToEntity(wealthMysql);
    }

    @Override
    public Wealth convertCassandraDomainToModel(WealthCassandra wealthCassandra) {
        if (wealthCassandra == null) {
            return null;
        }
        return copyCassandraToEntity(wealthCassandra);
    }

    private static Wealth copyMysqlToEntity(WealthMysql wealthMysql) {
        Wealth wealth=new Wealth();
        wealth.setId(wealthMysql.getId());
        wealth.setUserName(wealthMysql.getUserName());
        wealth.setRechargePoint(wealthMysql.getRechargePoint());
        wealth.setState(wealthMysql.getState());
        wealth.setPlatformNo(wealthMysql.getPlatformNo());
        wealth.setCreateTime(wealthMysql.getCreateTime());
        wealth.setUpdateTime(wealthMysql.getUpdateTime());
        wealth.setVersion(wealthMysql.getVersion());
        return wealth;
    }

    private static Wealth copyCassandraToEntity(WealthCassandra wealthCassandra) {
        Wealth wealth=new Wealth();
        wealth.setId(wealthCassandra.getId());
        wealth.setUserName(wealthCassandra.getUserName());
        wealth.setRechargePoint(wealthCassandra.getRechargePoint());
        wealth.setState(wealthCassandra.getState());
        wealth.setPlatformNo(wealthCassandra.getPlatformNo());
        //wealth.setCreateTime(wealthCassandra.getCreateTime());
        //wealth.setUpdateTime(wealthCassandra.getUpdateTime());
        //wealth.setVersion(wealthCassandra.getVersion());
        return wealth;
    }

    private static WealthMysql copyEntityToMysql(Wealth wealth) {
        WealthMysql wealthMysql=new WealthMysql();
        wealthMysql.setId(wealth.getId());
        wealthMysql.setUserName(wealth.getUserName());
        wealthMysql.setRechargePoint(wealth.getRechargePoint());
        wealthMysql.setState(wealth.getState());
        wealthMysql.setPlatformNo(wealth.getPlatformNo());
        wealthMysql.setCreateTime(wealth.getCreateTime());
        wealthMysql.setUpdateTime(wealth.getUpdateTime());
        wealthMysql.setVersion(wealth.getVersion());
        return wealthMysql;
    }

    private static WealthCassandra copyEntityToCassandra(Wealth wealth) {
        WealthCassandra wealthCassandra=new WealthCassandra();
        wealthCassandra.setId(wealth.getId());
        wealthCassandra.setUserName(wealth.getUserName());
        wealthCassandra.setRechargePoint(wealth.getRechargePoint());
        wealthCassandra.setState(wealth.getState());
        wealthCassandra.setPlatformNo(wealth.getPlatformNo());
        //wealthCassandra.setCreateTime(wealth.getCreateTime());
        //wealthCassandra.setUpdateTime(wealth.getUpdateTime());
        //wealthCassandra.setVersion(wealth.getVersion());
        return wealthCassandra;
    }
}
